var TSUI;
(function (TSUI) {
    (function (Events) {
        var Event = (function () {
            function Event() {
                this.Handlers = [];
                this.OnHandlerAttached = null;
                this.OnHandlerAttachedContext = null;
                this.OnHandlerDettached = null;
                this.OnHandlerDettachedContext = null;
            }
            Event.prototype.Attach = function (handler) {
                if (!this.IsAttached(handler)) {
                    this.Handlers.push(handler);
                    if (this.OnHandlerAttached !== null) {
                        this.OnHandlerAttached.call(this.OnHandlerAttachedContext);
                    }
                }
            };

            Event.prototype.Detach = function (handler) {
                if (this.IsAttached(handler)) {
                    this.Handlers.splice(this.Handlers.indexOf(handler), 1);
                    if (this.OnHandlerDettached !== null) {
                        this.OnHandlerDettached.call(this.OnHandlerDettachedContext);
                    }
                }
            };

            Event.prototype.IsAttached = function (handler) {
                return this.Handlers.indexOf(handler) > -1;
            };

            Event.prototype.Invoke = function (args) {
                for (var i = 0; i < this.Handlers.length; i++) {
                    this.Handlers[i].Invoke(args);
                }
            };
            return Event;
        })();
        Events.Event = Event;

        var EventHandler = (function () {
            function EventHandler(Callback, Context) {
                this.Callback = Callback;
                this.Context = Context;
            }
            EventHandler.prototype.Invoke = function (args) {
                this.Callback.call(this.Context, args);
            };
            return EventHandler;
        })();
        Events.EventHandler = EventHandler;

        var EventArgs = (function () {
            function EventArgs(Sender) {
                this.Sender = Sender;
            }
            return EventArgs;
        })();
        Events.EventArgs = EventArgs;
    })(TSUI.Events || (TSUI.Events = {}));
    var Events = TSUI.Events;
})(TSUI || (TSUI = {}));
